package accounts;
import tester.cobertura.Instrument;

/**
 * @author Adam Blackwell
 */
// to represent a line of credit account in a bank
@Instrument 
public class Credit extends Account {

	public int creditLine; // the total amount of money they may have access to.
	public double interest; // The APR at which they are charged

	// Constructor.
	public Credit(int num, String name, int balance, 
			String owner, int creditLine, double interest) {
		super(num, name, balance, owner);
		this.creditLine = creditLine;
		this.interest = interest;

	}

	/*
	 * TEMPLATE: FIELDS: 
	 * ... num ...        -- int 
	 * ... balance ...    -- int 
	 * ... name ...       -- String 
	 * ... creditLine ... -- int 
	 * ... interest ...   -- double
	 * 
	 * METHODS: 
	 * ... deposit(int amt) ...  -- Account 
	 * ... withdraw(int amt) ... -- Account
	 */

	// produce an updated account after paying off the given amount
	@Override
	public Account deposit(int amt) {
		if (balance - amt < 0) {
			throw new RuntimeException("Cannot have a credit on your account.");
		} else {
			return new Credit(this.num, this.name, this.balance - amt, this.owner,
					this.creditLine, this.interest);
		}
	}

	// produce an updated account after borrowing the given amount
	@Override
	public Account withdraw(int amt) {
		if (balance + amt > creditLine) {
			throw new RuntimeException("Cannot spend above your credit line "
					+ this.name + ".");
		} else {
			return new Credit(this.num, this.name, this.balance + amt, this.owner,
					this.creditLine, this.interest);
		}
	}
}